<template>
  <div
    class="MyMenu"
    :style="{
      width: isCollapse ? '64px' : '200px',
    }"
  >
    <div class="logoBox" v-if="logo">
      <el-image class="logo" :src="logo" fit="contain">
        <div slot="error" class="image-slot"></div>
      </el-image>
      <transition name="el-fade-in">
        <div class="titleBox" v-if="title && !isCollapse">
          {{ title }}
        </div>
      </transition>
    </div>

    <!--    <div >-->
    <el-scrollbar class="hideScrollBar" style="height: 100%; width: 100%">
      <div class="menuBox hideScrollBar">
        <el-menu
          class="el-menu"
          @open="handleOpen"
          @close="handleClose"
          background-color="#fff"
          :active-text-color="theme"
          :router="true"
          :default-active="$route.path"
          :unique-opened="true"
          :collapse="isCollapse"
          :collapse-transition="true"
        >
          <m-menu-item
            :data="item"
            v-for="item in menu"
            :key="item.path"
          ></m-menu-item>
        </el-menu>
      </div>
    </el-scrollbar>
    <!--    </div>-->
    <div
      class="toggleCollapse"
      :class="{ collapse: isCollapse }"
      @click="toggleisCollapse"
    >
      <i class="icon el-icon-arrow-left"></i>
    </div>
  </div>
</template>

<script>
import MMenuItem from "./MMenuItem";
export default {
  name: "MMenu",
  data() {
    return {};
  },
  components: {
    MMenuItem,
  },
  props: {
    logo: {
      type: [Object, String],
    },
    title: {
      type: String,
    },
    isCollapse: {
      type: Boolean,
      default: false,
    },
  },
  computed: {
    menu() {
      return this.$store.state.MUI.MMenu.data;
    },
    theme() {
      return this.$store.state.MUI.settings.theme;
    },
  },
  mounted() {},
  methods: {
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      // console.log(key, keyPath);
    },
    toggleisCollapse() {
      this.$emit("update:isCollapse", !this.isCollapse);
    },
  },
};
</script>

<style lang="scss">
@import "@/MUI/style/var.scss";

$menuBackgroundColor: #fff;
$menuBackgroundColorActive: mix($mainColor, #fff, 10%);
$menuColor: rgba(0, 0, 0, 0.8);
//rgb(48, 65, 86);
.MyMenu {
  //width: px2(200);
  height: 100%;
  background-color: $menuBackgroundColor;
  color: $menuColor;
  padding-top: px2(84);
  padding-bottom: px2(50);
  box-sizing: border-box;
  border-right: px2(1) solid $borderColor;
  position: relative;
  transition: width 0.4s;
  .menuBox {
    height: 100%;
    width: 100%;
    overflow-x: hidden;
    padding-bottom: px2(40);

    .menu-icon {
      display: inline-block;
      margin-right: px2(4);
      width: px2(20);
    }
  }

  .logoBox {
    margin: 0 auto;
    text-align: center;
    padding: px2(25) px2(0);
    height: px2(80);
    width: 100%;
    position: absolute;
    top: 0;
    left: 0;
    text-align: center;
    white-space: nowrap;
    .logo {
      display: inline-block;
      margin: 0 auto;
      max-width: 80%;
      height: px2(30);
      margin-bottom: px2(10);
      //margin-right: px2(10);
      //margin-left: px2(10);
      padding: 0 px2(10);
    }
    .titleBox {
      vertical-align: top;
      max-width: px2(120);
      display: inline-block;
      color: $menuColor;
      margin: 0 auto;
      text-align: center;
      line-height: px2(30);
      font-size: px2(16);
      font-weight: bold;
    }
  }
  .toggleCollapse {
    position: absolute;
    bottom: px2(1);
    left: 0;
    text-align: center;
    width: 100%;
    height: px2(48);
    line-height: px2(48);
    border-top: px2(1) solid $borderColor;
    background: #fff;
    &:hover {
      background: $menuBackgroundColorActive;
      color: $mainColor;
      cursor: pointer;
    }
    &.collapse {
      .icon {
        transform: rotateY(180deg);
      }
    }
  }
}

.el-submenu {
  &.is-active {
    .el-submenu__title {
      color: $mainColor !important;
      .menu-icon {
        color: $mainColor;
      }
    }
  }
}

.el-menu {
  height: 100%;
  width: 100%;
  border: 0 !important;
  color: $menuColor;
  background-color: $menuBackgroundColor;
}

.el-submenu__title {
  color: $menuColor !important;
}
.el-menu-item {
  color: $menuColor;
}

.el-menu-item:hover,
.el-submenu__title:hover {
  background-color: $menuBackgroundColorActive !important;
}
.el-menu-item.is-active {
  &:after {
    content: "";
    display: inline-block;
    width: px2(4);
    height: 100%;
    position: absolute;
    right: 1px;
    top: 0;
    // background-color: $mainColor;
  }
  .menu-icon {
  }
}

.el-menu-item-group {
  background-color: $menuBackgroundColor !important;
  .el-menu-item-group__title {
    padding: 0;
  }
}
</style>
